Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

487
Views
Node Fetch blobFromSync and blobFrom TypeError [ERR_INVALID_URL]: Invalid URL

I am trying to read a file that is local to my computer into a blob using the node-fetch library, but each time I do, I get this Invalid Url Error. My code is the following:

const express = require('express');
const cors = require('cors');
const bodyParser = require("body-parser");


const fetch = (...args) =>
  import('node-fetch').then(({ default: fetch }) => fetch(...args));

const blobFromSync = (...args) =>
  import('node-fetch').then(({ blobFromSync }) => fetch(...args));

  const blobFrom = (...args) =>
  import('node-fetch').then(({ blobFrom }) => fetch(...args));

  const fileFrom = (...args) =>
  import('node-fetch').then(({ fileFrom }) => fetch(...args));



const app = express();
const port = 3000;

//Here we are configuring express to use body-parser as middle-ware.
app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.use(function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*")
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
    next()
});


app.get('/recorded', async (req, res) => {

    try {
   
        let file_location = './path/to/video.mp4';

        const file = fileFrom(file_location);

        const chunkSize = 40000

        for (let start = 0; start < file.size; start += chunkSize) {
            const chunk = file.slice(start, start + chunkSize + 1)
            //Will eventuay doa fetch
            //await fetch(url, { method: 'post', body: chunk, headers: headers, }).then(res => res.text())
        }

        res.status(200);
        res.send().end();
    } catch (e) {
        console.log(e);
    }
});


app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
});

The error is the following (its also uncatchable):

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:377:5)
    at URL.onParseError (node:internal/url:563:9)
    at new URL (node:internal/url:643:5)
    at new Request (file:///Users/xxxxxx/Development/terminal-backend/node_modules/node-fetch/src/request.js:55:16)
    at file:///Users/xxxx/Development/terminal-backend/node_modules/node-fetch/src/index.js:51:19
    at new Promise (<anonymous>)
    at fetch (file:///Users/xxxx/Development/terminal-backend/node_modules/node-fetch/src/index.js:49:9)
    at /Users/xxxxx/Development/terminal-backend/src/server.js:11:53 {
  input: './path/to/video.mp4',
  code: 'ERR_INVALID_URL'
}

blobFromSync and blobFrom also throw the same error. If this is a local file, why am I get invalid url?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!